package org.example.config;

import feign.Logger;
import feign.Request;
import org.example.feign.interceptor.ProducerFeignInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class OpenFeignConfig {
    @Value("${feign.logger-level}")
    private String feignLoggerLevel;

    @Bean
    public Logger.Level feignLoggerLevel() {
        Logger.Level level;
        if ("debug".equalsIgnoreCase(feignLoggerLevel)) {
            level = Logger.Level.FULL;
        } else {
            level = Logger.Level.NONE;
        }

        return level;
    }

    //    可以使用yaml或@Bean任选其一
    @Bean
    public Request.Options options() {
        // 连接超时时间，默认2000ms
        // 请求处理超时时间，默认5000ms
        return new Request.Options(2, TimeUnit.SECONDS, 5, TimeUnit.SECONDS, true);
    }

    @Bean
    public ProducerFeignInterceptor producerFeignInterceptor() {
        return new ProducerFeignInterceptor();
    }
}
